﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using KeaoBase;

namespace KeaoMDS.InfoManage
{
    public partial class YunShuGongSiGuanLi : BaseForm
    {
        public YunShuGongSiGuanLi()
        {
            InitializeComponent();
        }

        private void YunShuGongSiGuanLi_Load(object sender, EventArgs e)
        {
            dataGridView1.AutoGenerateColumns = false;
            BindInfo();
        }

        private void menu_1_xinzeng_Click(object sender, EventArgs e)
        {
            if (!string.Format("{0}", KeaoUtils._CurrentUserRow["juesequanxian"]).Contains("运输公司管理"))
            {
                KeaoUtils.ShowInfoMessage("该用户没有操作权限。");
                return;
            }
            
            YunShuGongSiBianJi yunBianJi = new YunShuGongSiBianJi();
            if (yunBianJi.ShowDialog() == DialogResult.OK)
            {
                BindInfo();
                dataGridView1.Rows[dataGridView1.Rows.Count - 1].Selected = true;
            }
        }

        private void menu_1_xiugai_Click(object sender, EventArgs e)
        {
            if (!string.Format("{0}", KeaoUtils._CurrentUserRow["juesequanxian"]).Contains("运输公司管理"))
            {
                KeaoUtils.ShowInfoMessage("该用户没有操作权限。");
                return;
            }
            
            if (dataGridView1.SelectedRows.Count==0)
            {
                return;
            }
            int selectIndex = dataGridView1.SelectedRows[0].Index;
            YunShuGongSiBianJi yunBianJi = new YunShuGongSiBianJi(dataGridView1.SelectedRows[0]);
            if (yunBianJi.ShowDialog() == DialogResult.OK)
            {
                BindInfo();
                dataGridView1.Rows[selectIndex].Selected = true;
            }
        }

        private void menu_1_shanchu_Click(object sender, EventArgs e)
        {
            if (!string.Format("{0}", KeaoUtils._CurrentUserRow["juesequanxian"]).Contains("运输公司管理"))
            {
                KeaoUtils.ShowInfoMessage("该用户没有操作权限。");
                return;
            }
            
            if (dataGridView1.SelectedRows.Count==0)
            {
                return;
            }

            if (KeaoUtils.ShowQuestionMessage("确定要删除该运输公司信息吗？") == DialogResult.Yes)
            {
                TableRow delRow = new TableRow() { TableName="tbl_yunshugongsi", ID=string.Format("{0}",dataGridView1.SelectedRows[0].Cells["col_id"].Value) };
                if (KeaoUtils._DB.DeleteRowByID(delRow) > 0)
                {
                    KeaoUtils.ShowInfoMessage("删除运输公司信息完成。");
                    BindInfo();
                }
            }
        }

        private void BindInfo()
        {
            DataTable Dt = KeaoUtils._DB.GetDataTableByCondition("tbl_yunshugongsi");
            dataGridView1.DataSource = Dt;
        }
    }
}
